<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台用户修改</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__ADMIN__css/bootstrap.min.css" rel="stylesheet">
    <link href="__ADMIN__css/font-awesome.min93e3.css" rel="stylesheet">
    <link href="__ADMIN__css/animate.min.css" rel="stylesheet">
    <link href="__ADMIN__css/style.min.css" rel="stylesheet">
    <link href="__ADMIN__js/plugins/layer/skin/default/layer.css" rel="stylesheet">
    <link rel="stylesheet" href="__ADMIN__css/plugins/switchery/switchery.css" />
    <style>
        .col-sm-4 img{
            height:100px;
            width:100px;
            margin-left: 110%;
            margin-top:-10%;
        }

    </style>
</head>
<body>
<div class="col-sm-12">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
         <h5>添加管理员</h5>
        </div>
        <div class="ibox-content">
            <form method="post" action="{:U('admin/save')}" id="forma" name="forma" class="form-horizontal">
                <div class="hr-line-dashed"></div>
                <input type="hidden" name="id" id="id" value="{$admininfo.id}">
                <div class="form-group">
                    <label class="col-sm-2 control-label">账号</label>
                    <div class="col-sm-10">
                        <input type="text" name="username" value="{$admininfo.name}" id="username" placeholder="请输入账号" class="form-control">
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group" id="files">
                    <label class="col-sm-2 control-label">头像上传</label>

                    <div class="col-sm-4">
                        <input type="file" name="litpic" id="litpic" class="form-control">
                        <if condition="$admininfo.img eq '' ">
                            <img src="/Upload/head/1492869608.jpg">
                            <elseif condition="file_exists($admininfo['img']) eq 1 "/>
                                <img src="/{$admininfo.img}">
                                <else/>
                                <img src="/Upload/head/1492869608.jpg">

                        </if>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">角色</label>

                    <div class="col-sm-10">
                        <select class="form-control m-b" name="pid" id="pid" data-value="{$admininfo.group_id}">
                            <option value="">-------角色1--------</option>
                            <volist name="list" id="vo">
                                <option value="{$vo.id}" <if condition="$vo['id'] == $admininfo['group_id']">selected</if> >{$vo.title}</option>
                            </volist>
                        </select>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">真实姓名</label>

                    <div class="col-sm-10">
                        <input type="text" name="realname" value="{$admininfo.realname}" data-value="{$admininfo.realname}" id="realname" placeholder="请输入真实姓名" class="form-control">
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">状态</label>

                    <div class="col-sm-10">
                        <input type="checkbox" data-value="{$admininfo.status}" name="status" id="status" value="1" class="js-switch" <if condition="$admininfo['status'] eq 1"> checked </if>>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="col-sm-4 col-sm-offset-2">
                    <button class="btn btn-primary" type="submit">保存内容</button>
                    <button class="btn btn-white" type="reset" onclick="history.go(-1)">取消</button>
                </div>
            </form>

        </div>
    </div>
</div>
<script src="__ADMIN__js/jquery.min.js"></script>
<script src="__ADMIN__js/bootstrap.min.js"></script>
<script src="__ADMIN__js/plugins/layer/layer.min.js"></script>
<script src="__ADMIN__js/plugins/switchery/switchery.js"></script>
<script src="__ADMIN__js/plugins/validate/jquery.validate.min.js"></script>
<script src="__ADMIN__js/plugins/validate/messages_zh.min.js"></script>
<script src="__ADMIN__js/jquery.form.js"></script>
<script src="__ADMIN__js/common.js"></script>
</body>
<script>
    $(function(){
        $("#forma").ajaxForm({
            beforeSerialize: changeValue,//在提交之前执行此项
            beforeSubmit:checkForm,
            success:complete,
            dataType:'JSON'
        });
        function complete(data){
            if(data.status > 0){
                common.error(data.msg);
            }else{
                common.success(data.msg,'{:U("admin/index")}');
            }
        }
        function checkForm(formData, jqForm, options){

        }
        function changeValue(){
            var pidobj = $('#pid'),oldpid = pidobj.data('value'),newpid = pidobj.val(),submit = false;//获取到原值和新值
            if(oldpid != newpid){ //原值不等于新值，说明值被改变
                if(newpid == ''){
                    common.error('请选择分组');//新值为空说明未选择
                    return false;
                }
                submit = true;
            }else{
                pidobj.removeAttr('name');//原值等于新值，说明值为改变，把此项的name移除掉使之不能提交
            }
            var rnameobj = $('#realname'),oldrname = rnameobj.data('value'),newrname = rnameobj.val();
            if(oldrname != newrname){
                if(newrname == ''){
                    common.error('请输入真实姓名');
                    return false;
                }
                submit = true;
            }else{
                rnameobj.removeAttr('name');
            }
            var newpic = $('#litpic').val();
            if(newpic != ''){
                submit = true;
            }
            if(!submit){
                common.success('修改成功','{:U("admin/index")}');
                return false;
            }
        }
    });
    var elem = document.querySelector('.js-switch');
    var switchery = new Switchery(elem, { });
</script>
</html>
